﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Pop填充其它控件 - 从表</title>
     <script language="JavaScript" src="../../../Comm/JScript.js" type="text/javascript" ></script>
    <script type="text/javascript" src="../../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet"  type="text/css" />
     
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script type="text/javascript" language="javascript" >

        var mapdtls = null;
        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=PopFullCtrlDtl_Init&FK_MapData=" + GetQueryString("FK_MapData") + "&KeyOfEn=" + GetQueryString("KeyOfEn") + "&MyPK=" + GetQueryString("MyPK") + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    data = JSON.parse(data);
                    mapdtls = data;

                    if (data.length == 0) {
                        alert('该表单没有从表组件.');
                        Back();
                        return;
                    }

                    var html = '';
                    for (var i = 0; i < data.length; i++) {

                        var mapdtl = data[i];

                        html += "<fieldset>";
                        html += "<legend>从表:" + mapdtl.No + " - " + mapdtl.Name + "</legend>";
                        html += '<textarea rows=4 name=TB_' + mapdtl.No + '  name=TB_' + mapdtl.No + ' style="width:95%;" > ' + mapdtl.MTR + '</textarea>';
                        html += "<br>可填充的明细表列:" + mapdtl.Alias;
                        html += "</fieldset>";
                    }

                    document.getElementById('tbs').innerHTML = html;
                    return;
                }
            });

            $("#Msg").html("");
        });

        //装载模版.
        function LoadTemplate() {
            var url = "../../SettingTemplate.htm?TemplateType=PopFullCtrl";
            WinOpen(url, 'ss');
        }
    </script>
</head>
<body >

<form id="cc">

<table id="table" style="width:100%;border-width:0px;" >
<caption>为文本框填充其它控件 - 从表 </caption>

<tr style="border-width:0px;" >
<td colspan="3" style="border-width:0px;" > 执行的SQL
<a href="javascript:ShowHidden('sqlexp')"  >填充SQL帮助: </a>

<div id='sqlexp'  style='color:Gray; display:none'>
<ul>
 <li>1. 设置一个查询的SQL语句，该SQL返回一个结果集，用于自动填充当前从表. </li>
 <li>2. 该SQL必须包含 @Key 关键字，@Key 输入文本框的值. </li>
 <li>3. SQL返回的列与该从表字段名称保持一致，就可以完成控件数据的自动填充。</li>
 <li>4. 比如:SELECT NianYue,GongZuoDanWei,ZhengMingRen,BeiZhu FROM Demo_Resume WHERE FK_Student='@Key' </li>
 <li>ccform为您准备了一个demo,请参考表单库\\本机数据源\\表单元素\\基础功能</li>
 <li><img alt="" src="../Img/TBCtrlFull.png" /></li>
 </ul>
</div>

 </td>
</tr>

<tr> 
<td colspan="3" style="width:100%;border-width:0px;"> 

<div id="tbs"> </div>

</td>
</tr>

<tr>
<td colspan="3" >

<input type="button" value="保存" onclick="Save()" id="Btn_Save" />
<input type="button" value="返回" onclick="Back()" id="Btn_Back" title = ""  />

 </td>
</tr>

</table>

<div id="Msg"> </div>

<script type="text/javascript">

    function Back() {
        var myPK = GetQueryString('MyPK');
        var fromPage = GetQueryString('FromPage');
        var url = '';
        if (fromPage == null)
            var url = 'PopFullCtrl.htm?FK_MapData=' + GetQueryString('FK_MapData') + '&MyPK=' + myPK + "&KeyOfEn=" + GetQueryString('KeyOfEn');
        else
            var url = 'DDLFullCtrl.htm?FK_MapData=' + GetQueryString('FK_MapData') + '&MyPK=' + myPK + "&KeyOfEn=" + GetQueryString('KeyOfEn');
        window.location.href = url;
        return;
    }
     
    function Save() {

        $("#Msg").html("正在保存,请稍后......");

        var str = "";
        var frmData = $("#cc").serialize();
        var myurl = Handler + "?DoType=PopFullCtrlDtl_Save&MyPK=" + GetQueryString("MyPK") + "&FK_MapData=" + GetQueryString('FK_MapData') + "&Tag="+str+"&m=" + Math.random();
        $.ajax({
            data: frmData,
            type: 'post',
            async: true,
            url: myurl,
            dataType: 'html',
            success: function (data) {

                if (data.indexOf('err@') != -1) {
                    $("#Msg").html("<font color=red>" + data + "</font>");
                    return;
                }

                alert(data);

                var mypk =   GetQueryString('MyPK');
                var url = 'PopFullCtrl.htm?FK_MapData=' + GetQueryString('FK_MapData') + '&KeyOfEn=' + GetQueryString('KeyOfEn') + '&MyPK=' + mypk;
                window.location.href = url; 
                return;
            },
            error: function (data) {
                alert(data);
            }
        });
    }

    function Delete() {

        if (window.confirm('您确定要删除吗？') == false)
            return false;

        $.ajax({
            type: 'post',
            async: true,
            url: Handler + "?DoType=PopFullCtrl_Delete&FK_MapData=" + GetQueryString("FK_MapData") + "&KeyOfEn=" + GetQueryString("KeyOfEn") + "&m=" + Math.random(),
            dataType: 'html',
            success: function (data) {
                alert(data);
                window.location.href = window.location.href;
                return;
            }
        });
    }
</script>
</form>
</body>
</html>
